import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;


public class CourseDao {

	public static ArrayList<Course> queryCourseList() {
		 ArrayList<Course> courseList = new ArrayList<>();
		/**
		 * 查询学生列表
		 */
			Connection conn = ConnectionUtil.getConnection();
	        Statement stmt = null;
	        try{
	           
	            // 执行查询
	            System.out.println(" 实例化Statement对象...");
	            stmt = conn.createStatement();
	            String sql;
	            
	            sql = "SELECT id, kcm, kss, xf, cj, kkxq FROM course join score "+ "on course.kch=score.kch";
	            ResultSet rs =  stmt.executeQuery(sql);
	        
	            // 展开结果集数据库
	            while(rs.next()){
	                // 通过字段检索
	                int id  = rs.getInt("id");
	                String kcm = rs.getString("kcm");
	                int kss = rs.getInt("kss");
	                int xf = rs.getInt("xf"); 
	                int cj = rs.getInt("cj");
	                int kkxq = rs.getInt("kkxq");
	                
	                Course course = new Course(id, kcm, kss, xf, cj, kkxq);
					courseList.add(course);
	            }
	        }catch(SQLException se){
	            // 处理 JDBC 错误
	            se.printStackTrace();
	        }catch(Exception e){
	            // 处理 Class.forName 错误
	            e.printStackTrace();
	        }
	        System.out.println("查询成功！");
	        return courseList;
	
	}
}
